package com.example.hcd.functionactivity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.AbsoluteLayout.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hcd.MenuActivity;
import com.example.hcd.R;
import com.example.hcd.VenadaOAApplication;
import com.example.hcd.adapt.ImageAndTextListAdapter;
import com.example.hcd.adapt.ReimburseListAdapt;
import com.example.hcd.datamanage.BorrowData;
import com.example.hcd.datamanage.BusniessTravelData;
import com.example.hcd.datamanage.ImageAndText;
import com.example.hcd.datamanage.JPushMessage;
import com.example.hcd.datamanage.LeaveData;
import com.example.hcd.datamanage.OutData;
import com.example.hcd.datamanage.OverTimeData;
import com.example.hcd.datamanage.ParseData;
import com.example.hcd.datamanage.PaymentData;
import com.example.hcd.datamanage.PeopleNextData;
import com.example.hcd.datamanage.ProjectChildData;
import com.example.hcd.datamanage.PurchaseData;
import com.example.hcd.datamanage.ReimburseData;
import com.example.hcd.datamanage.SealuseData;
import com.example.hcd.datamanage.TaskTodoInfo;
import com.example.hcd.datamanage.UseCarData;
import com.example.hcd.datamanage.UserInfo;
import com.example.hcd.internet.FileUtils;
import com.example.hcd.internet.InternetKeep;
import com.example.hcd.internet.LinkHelp;
import com.example.hcd.internet.URLS;
import com.example.hcd.tool.CommonDialog;
import com.example.hcd.tool.Constants;
import com.example.hcd.tool.DigitalTool;
import com.example.hcd.tool.MyGridView;
import com.example.hcd.tool.MyLoadingDialog;
import com.example.hcd.tool.ToastHelp;
import com.example.hcd.tool.URLImageParser;
import com.example.hcd.tool.XListView;
import com.wheel.StrericWheelAdapter;
import com.wheel.WheelView;

import cn.jpush.android.api.JPushInterface;

//任务详情
public class TaskInfo extends BaseActivity implements OnClickListener, OnItemClickListener {
    // 任务类型
    private String type;
    // 任务ID
    private String taskId;
    // 流程ID
    private String processId;
    // 业务ID
    private String Id;
    // 是否是待办事项
    private boolean isTaskTodo;
    private ImageView right_btn;
    private EditText suggestion;
    private TextView isAgree;
    // 是否同意下拉popwindows
    private CommonDialog useCarDialog;
    // private View popView;

    // 是否有下一步处理人
    private CommonDialog nextPeopleDialog;
    private View popView1;

    // 查看报销详情
    private PopupWindow popipwindow2;
    private View popView2;

    private ArrayList<PeopleNextData> peoples_next;
    private TextView nextPeople;
    private RelativeLayout nextPeopleBg;
    private String workUserId;

    private TaskInfo context;
    private LayoutInflater inflater;
    private View main_view;

    private String task_DEF_KEY_ = "";

    private TextView view_title;

    // 滚动时间
    private TextView timeedit;
    private TextView timeedit1;
    private WheelView yearWheel, monthWheel, dayWheel, hourWheel, minuteWheel;
    public static String[] yearContent = null;
    public static String[] monthContent = null;
    public static String[] dayContent = null;
    public static String[] hourContent = null;
    public static String[] minuteContent = null;

    // 流程跟踪
    private ArrayList<TaskTodoInfo> flowTraceList;
    private LinearLayout flowtrace;
    private MyGridView gridView;
    private ImageAndTextListAdapter adapter;
    private List<ImageAndText> listImageAndText;

    // 付款类型
    private String paytype;

    // 是否是关联界面
    private boolean isRelation;
    // 是否显示关联报销（借款界面）
    private boolean isShowReimburseOrBorrow;
    // 是否确认还款状态 假如是就把是否同意改成确认还款
    private boolean isSureBackMoney;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
//        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
//                .detectDiskReads().detectDiskWrites().detectNetwork()
//                .penaltyLog().build());
//        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
//                .detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
//                .penaltyLog().penaltyDeath().build());
        mPageName = "TaskInfo";
        // 获取任务类型\id、流程id
        context = this;
        inflater = LayoutInflater.from(this);


        if (!getIntent().hasExtra(Constants.NOTIFICATION)) {
            type = getIntent().getStringExtra("TASK_TYPE");
            taskId = getIntent().getStringExtra("taskId");
            processId = getIntent().getStringExtra("processId");
            // 是否是待办事项
            isTaskTodo = getIntent().getBooleanExtra("IS_TASK_TODO", isTaskTodo);
            isRelation = getIntent().getBooleanExtra("IS_RELATATION", isRelation);
            if(getIntent().hasExtra(task_DEF_KEY_)) {
                task_DEF_KEY_ = getIntent().getStringExtra("task_DEF_KEY_");
            }


        } else {
            JPushMessage mNotification = (JPushMessage) getIntent().getSerializableExtra(Constants.NOTIFICATION);
            type = mNotification.getProcessType();
            taskId = mNotification.getTaskId();
            processId = mNotification.getProcessInstanceId();
            // 是否是待办事项
            isTaskTodo = mNotification.getIsTaskToDo().equals("true") ? true : false;
            if (null != mNotification.getHasBorrow()) {
                isRelation = mNotification.getHasBorrow().equals("true") ? true : false;
            }
            if (null != mNotification.getFlowKey()) {
                task_DEF_KEY_ = mNotification.getFlowKey();
            }
        }

        main_view = getMainViewByType();
        // 初始化布局
        if (main_view == null) {
            // Toast.makeText(context, "获取任务类型失败", Toast.LENGTH_SHORT).show();
            ToastHelp.doToast(this, "获取任务类型失败");
            finish();
        } else {
            setContentView(main_view);

            view_title = (TextView) main_view.findViewById(R.id.title_content);

            // 设置返回
            ImageView backbtn = (ImageView) main_view.findViewById(R.id.title_bar_btn_left);
            backbtn.setOnClickListener(context);
            flowtrace = (LinearLayout) main_view.findViewById(R.id.addflowtrace);
            peoples_next = new ArrayList<PeopleNextData>();
            flowTraceList = new ArrayList<TaskTodoInfo>();
            right_btn = (ImageView) main_view.findViewById(R.id.title_bar_btn_right);

            if (!isTaskTodo) {
                LinearLayout istasktodo = (LinearLayout) main_view.findViewById(R.id.task_todo_bg);
                istasktodo.setVisibility(View.GONE);
                right_btn.setVisibility(View.GONE);

                if (type.equals("sealApp")) {
                    view_title.setText("查看详情");
                    RelativeLayout yuji_return = (RelativeLayout) main_view.findViewById(R.id.yuji_return);
                    yuji_return.setVisibility(View.GONE);
                }
            } else {
                // 待办事项里出现下一步处理人
                initNextPeople();

                if (type.equals("sealApp")) {

                    if (task_DEF_KEY_.equals("sealback")) {
                        view_title.setText("确认归还");
                        LinearLayout istasktodo = (LinearLayout) main_view.findViewById(R.id.task_todo_bg);
                        istasktodo.setVisibility(View.GONE);

                        TextView title4 = (TextView) main_view.findViewById(R.id.title4);
                        title4.setText("预计归还时间");

                        timeedit = (TextView) main_view.findViewById(R.id.title81);
                        main_view.findViewById(R.id.btn_image2).setOnClickListener(this);
                        initContent();

                    } else if (task_DEF_KEY_.contains("usertask")) {
                        TextView title4 = (TextView) main_view.findViewById(R.id.title4);
                        title4.setText("预计归还时间");

                        RelativeLayout yuji_return = (RelativeLayout) main_view.findViewById(R.id.yuji_return);
                        yuji_return.setVisibility(View.GONE);

                    } else {
                        view_title.setText("确认归还");
                        LinearLayout istasktodo = (LinearLayout) main_view.findViewById(R.id.task_todo_bg);
                        istasktodo.setVisibility(View.GONE);

                        timeedit = (TextView) main_view.findViewById(R.id.title81);
                        main_view.findViewById(R.id.btn_image2).setOnClickListener(this);

                        initContent();

                    }

                }

            }

            initView();
        }

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        if (!intent.hasExtra(Constants.NOTIFICATION)) {
            type = intent.getStringExtra("TASK_TYPE");
            taskId = intent.getStringExtra("taskId");
            processId = intent.getStringExtra("processId");
            // 是否是待办事项
            isTaskTodo = intent.getBooleanExtra("IS_TASK_TODO", isTaskTodo);
            isRelation = intent.getBooleanExtra("IS_RELATATION", isRelation);
            task_DEF_KEY_ = intent.getStringExtra("task_DEF_KEY_");

        } else {
            JPushMessage mNotification = (JPushMessage) intent.getSerializableExtra(Constants.NOTIFICATION);
            type = mNotification.getProcessType();
            taskId = mNotification.getTaskId();
            processId = mNotification.getProcessInstanceId();
            Log.e("task", taskId+"");
            Log.e("task", processId+"");
            // 是否是待办事项
            isTaskTodo = mNotification.getIsTaskToDo().equals("true") ? true : false;
            if (null != mNotification.getHasBorrow()) {
                isRelation = mNotification.getHasBorrow().equals("true") ? true : false;
            }
            if (null != mNotification.getFlowKey()) {
                task_DEF_KEY_ = mNotification.getFlowKey();
            }
        }
        main_view = getMainViewByType();
        // 初始化布局
        if (main_view == null) {
            // Toast.makeText(context, "获取任务类型失败", Toast.LENGTH_SHORT).show();
            ToastHelp.doToast(this, "获取任务类型失败");
            finish();
        } else {
            setContentView(main_view);


            view_title = (TextView) main_view.findViewById(R.id.title_content);

            // 设置返回
            ImageView backbtn = (ImageView) main_view.findViewById(R.id.title_bar_btn_left);
            backbtn.setOnClickListener(context);
            flowtrace = (LinearLayout) main_view.findViewById(R.id.addflowtrace);
            peoples_next = new ArrayList<PeopleNextData>();
            flowTraceList = new ArrayList<TaskTodoInfo>();
            right_btn = (ImageView) main_view.findViewById(R.id.title_bar_btn_right);

            if (!isTaskTodo) {
                LinearLayout istasktodo = (LinearLayout) main_view.findViewById(R.id.task_todo_bg);
                istasktodo.setVisibility(View.GONE);
                right_btn.setVisibility(View.GONE);

                if (type.equals("sealApp")) {
                    view_title.setText("查看详情");
                    RelativeLayout yuji_return = (RelativeLayout) main_view.findViewById(R.id.yuji_return);
                    yuji_return.setVisibility(View.GONE);
                }
            } else {
                // 待办事项里出现下一步处理人
                initNextPeople();
                if (type.equals("sealApp")) {
                    if (task_DEF_KEY_.equals("sealback")) {
                        view_title.setText("确认归还");
                        LinearLayout istasktodo = (LinearLayout) main_view.findViewById(R.id.task_todo_bg);
                        istasktodo.setVisibility(View.GONE);

                        TextView title4 = (TextView) main_view.findViewById(R.id.title4);
                        title4.setText("预计归还时间");

                        timeedit = (TextView) main_view.findViewById(R.id.title81);
                        main_view.findViewById(R.id.btn_image2).setOnClickListener(this);
                        initContent();

                    } else if (task_DEF_KEY_.contains("usertask")) {
                        TextView title4 = (TextView) main_view.findViewById(R.id.title4);
                        title4.setText("预计归还时间");

                        RelativeLayout yuji_return = (RelativeLayout) main_view.findViewById(R.id.yuji_return);
                        yuji_return.setVisibility(View.GONE);

                    } else {
                        view_title.setText("确认归还");
                        LinearLayout istasktodo = (LinearLayout) main_view.findViewById(R.id.task_todo_bg);
                        istasktodo.setVisibility(View.GONE);

                        timeedit = (TextView) main_view.findViewById(R.id.title81);
                        main_view.findViewById(R.id.btn_image2).setOnClickListener(this);

                        initContent();

                    }

                }

            }

            initView();
        }

    }

    private void initNextPeople() {
        nextPeopleBg = (RelativeLayout) main_view.findViewById(R.id.next_people_bg);
        nextPeopleBg.setVisibility(View.VISIBLE);

        nextPeople = (TextView) main_view.findViewById(R.id.next_people);

    }

    private void addFlowTrace() {
        getFlowTrace flow = new getFlowTrace();
        flow.execute();
    }

    private void initView() {
        // 添加流程跟踪
        addFlowTrace();
        // 获取流程信息
        LoadTaskInfo taskinfo = new LoadTaskInfo();
        taskinfo.execute();
    }

    private View getMainViewByType() {
        View main = null;
        if (type.contains("ExpenseSale") || type.contains("ExpenseSale-suz")) {
            main = inflater.inflate(R.layout.reimburse_detail_view, null);
        } else if (type.contains("payForment") || type.contains("payForment-suz02")
                || type.contains("payForment-suz01")) {
            main = inflater.inflate(R.layout.payment_detail_view, null);
        } else if (type.contains("borrow")) {
            main = inflater.inflate(R.layout.borrow_detail_view, null);
        } else if (type.contains("purchase")) {
            main = inflater.inflate(R.layout.purchase_detail_view, null);
        } else if (type.contains("sealApp")) {
            main = inflater.inflate(R.layout.sealuse_detail_view, null);
        } else if (type.contains("workOvertime")) {
            main = inflater.inflate(R.layout.overtime_detail_view, null);
        } else if (type.contains("daysOff")) {
            main = inflater.inflate(R.layout.off_detail_view, null);
        } else if (type.contains("leave")) {
            main = inflater.inflate(R.layout.leave_detail_view, null);
        } else if (type.contains("outgoing")) {
            main = inflater.inflate(R.layout.use_car_detail, null);
            initContent();
        } else if (type.contains("businessTravel")) {
            main = inflater.inflate(R.layout.bussiness_travel_detail_view, null);
        }

        return main;
    }

    public void initTaskTodoInfo() {
        right_btn.setOnClickListener(context);
        // 是否同意
        isAgree = (TextView) main_view.findViewById(R.id.is_agree_btn);
        isAgree.setText("同意");
        suggestion = (EditText) main_view.findViewById(R.id.editText20);
        isAgree.setOnClickListener(context);
        main_view.findViewById(R.id.btn_image1).setOnClickListener(context);

        initPopView();
    }

    public void initPopView1() {
        nextPeople.setOnClickListener(this);

        popView1 = inflater.inflate(R.layout.my_popup_view, null);
        // 报销项目

        LinearLayout addline1 = (LinearLayout) popView1.findViewById(R.id.addline);

        nextPeopleDialog = new CommonDialog(this);

        for (int i = 0; i < peoples_next.size(); i++) {
            final View item = (View) inflater.inflate(R.layout.common_dialog_item, null);
            final TextView text = (TextView) item.findViewById(R.id.item_text);
            text.setText(peoples_next.get(i).getUserName() + "(" + peoples_next.get(i).getDepartmentName()
                    + ")");
            nextPeopleDialog.addView(item);
            final String id = peoples_next.get(i).getUserId();

            text.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    nextPeople.setText(text.getText().toString());
                    workUserId = id;
                    nextPeopleDialog.dismiss();
                }
            });


        }

    }

    public void initPopView2(ArrayList<ReimburseData> array) {
        popView2 = inflater.inflate(R.layout.my_task_list_view, null);
        // 报销项目

        ImageView cancel = (ImageView) popView2.findViewById(R.id.title_bar_btn_left);
        cancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                popipwindow2.dismiss();
            }
        });

        // 刷新
        ImageView refreshBtn = (ImageView) popView2.findViewById(R.id.title_bar_btn_right);
        refreshBtn.setVisibility(View.GONE);

        TextView title_content = (TextView) popView2.findViewById(R.id.title_content);
        title_content.setText("关联报销列表");
        XListView list = (XListView) popView2.findViewById(R.id.lists);
        list.setPullLoadEnable(false);
        list.setPullRefreshEnable(false);

        final ReimburseListAdapt adapt = new ReimburseListAdapt(context);
        adapt.setisLookDetail(true);
        list.setAdapter(adapt);
        adapt.setList(array);
        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                // TODO Auto-generated method stub
                ReimburseData data = adapt.getItem(arg2 - 1);
                Intent intent = new Intent(context, TaskInfo.class);
                intent.putExtra("taskId", data.getId());
                intent.putExtra("processId", data.getProcessInstanceId());
                intent.putExtra("TASK_TYPE", "ExpenseSale");
                intent.putExtra("IS_TASK_TODO", false);
                intent.putExtra("NO_SHOW_REIMBURSE_BORROW", true);
                startActivity(intent);
            }
        });
        list.removeFooterViews();

        popipwindow2 = new PopupWindow(popView2, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        // 这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景（很神奇的）
        popipwindow2.setBackgroundDrawable(new BitmapDrawable());
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        int id = arg0.getId();
        switch (id) {
            case R.id.title_bar_btn_left:
                finish();
                break;
            case R.id.title_bar_btn_right:
                upload();
                break;
            case R.id.btn_image1:
            case R.id.is_agree_btn:
                if (!isSureBackMoney) {
                    Window window = useCarDialog.getWindow();
                    window.setGravity(Gravity.BOTTOM);
                    window.setWindowAnimations(R.style.pop_float_win_anim_style);
                    useCarDialog.show();
                }

                break;

            case R.id.next_people:
                Window window = useCarDialog.getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setWindowAnimations(R.style.pop_float_win_anim_style);
                nextPeopleDialog.show();
                break;
            case R.id.title413:
                popipwindow2.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
                popipwindow2.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
                popipwindow2.showAtLocation(main_view, Gravity.NO_GRAVITY, 0, 0);
                // 设置允许在外点击消失
                popipwindow2.setOutsideTouchable(true);
                popipwindow2.setFocusable(true);
                popipwindow2.update();
                break;
            case R.id.title81:
            case R.id.btn_image2: {
                {
                    View view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.time_picker,
                            null);

                    Calendar calendar = Calendar.getInstance();
                    int curYear = calendar.get(Calendar.YEAR);
                    int curMonth = calendar.get(Calendar.MONTH) + 1;
                    int curDay = calendar.get(Calendar.DAY_OF_MONTH);
                    int curHour = calendar.get(Calendar.HOUR_OF_DAY);
                    int curMinute = calendar.get(Calendar.MINUTE);
                    int curSecond = calendar.get(Calendar.SECOND);

                    yearWheel = (WheelView) view.findViewById(R.id.yearwheel);
                    monthWheel = (WheelView) view.findViewById(R.id.monthwheel);
                    dayWheel = (WheelView) view.findViewById(R.id.daywheel);
                    hourWheel = (WheelView) view.findViewById(R.id.hourwheel);
                    minuteWheel = (WheelView) view.findViewById(R.id.minutewheel);

                    AlertDialog.Builder builder = new AlertDialog.Builder(context);
                    builder.setView(view);

                    yearWheel.setAdapter(new StrericWheelAdapter(yearContent));
                    yearWheel.setCurrentItem(curYear - 2013);
                    yearWheel.setCyclic(true);
                    yearWheel.setInterpolator(new AnticipateOvershootInterpolator());

                    monthWheel.setAdapter(new StrericWheelAdapter(monthContent));

                    monthWheel.setCurrentItem(curMonth - 1);

                    monthWheel.setCyclic(true);
                    monthWheel.setInterpolator(new AnticipateOvershootInterpolator());

                    dayWheel.setAdapter(new StrericWheelAdapter(dayContent));
                    dayWheel.setCurrentItem(curDay - 1);
                    dayWheel.setCyclic(true);
                    dayWheel.setInterpolator(new AnticipateOvershootInterpolator());

                    hourWheel.setAdapter(new StrericWheelAdapter(hourContent));
                    hourWheel.setCurrentItem(curHour);
                    hourWheel.setCyclic(true);
                    hourWheel.setInterpolator(new AnticipateOvershootInterpolator());

                    minuteWheel.setAdapter(new StrericWheelAdapter(minuteContent));
                    minuteWheel.setCurrentItem(curMinute);
                    minuteWheel.setCyclic(true);
                    minuteWheel.setInterpolator(new AnticipateOvershootInterpolator());

                    builder.setTitle("选取时间");
                    builder.setPositiveButton("确  定", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            StringBuffer sb = new StringBuffer();
                            sb.append(yearWheel.getCurrentItemValue()).append("-").append(monthWheel.getCurrentItemValue())
                                    .append("-").append(dayWheel.getCurrentItemValue());

                            sb.append(" ");
                            sb.append(hourWheel.getCurrentItemValue()).append(":")
                                    .append(minuteWheel.getCurrentItemValue());
                            timeedit.setText(sb);
                            dialog.cancel();
                        }
                    });

                    builder.show();

                }
            }
            break;
            case R.id.timeText:
            {
                View view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.time_picker,
                        null);

                Calendar calendar = Calendar.getInstance();
                int curYear = calendar.get(Calendar.YEAR);
                int curMonth = calendar.get(Calendar.MONTH) + 1;
                int curDay = calendar.get(Calendar.DAY_OF_MONTH);
                int curHour = calendar.get(Calendar.HOUR_OF_DAY);
                int curMinute = calendar.get(Calendar.MINUTE);
                int curSecond = calendar.get(Calendar.SECOND);

                yearWheel = (WheelView) view.findViewById(R.id.yearwheel);
                monthWheel = (WheelView) view.findViewById(R.id.monthwheel);
                dayWheel = (WheelView) view.findViewById(R.id.daywheel);
                hourWheel = (WheelView) view.findViewById(R.id.hourwheel);
                minuteWheel = (WheelView) view.findViewById(R.id.minutewheel);

                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setView(view);

                yearWheel.setAdapter(new StrericWheelAdapter(yearContent));
                yearWheel.setCurrentItem(curYear - 2013);
                yearWheel.setCyclic(true);
                yearWheel.setInterpolator(new AnticipateOvershootInterpolator());

                monthWheel.setAdapter(new StrericWheelAdapter(monthContent));

                monthWheel.setCurrentItem(curMonth - 1);

                monthWheel.setCyclic(true);
                monthWheel.setInterpolator(new AnticipateOvershootInterpolator());

                dayWheel.setAdapter(new StrericWheelAdapter(dayContent));
                dayWheel.setCurrentItem(curDay - 1);
                dayWheel.setCyclic(true);
                dayWheel.setInterpolator(new AnticipateOvershootInterpolator());

                hourWheel.setAdapter(new StrericWheelAdapter(hourContent));
                hourWheel.setCurrentItem(curHour);
                hourWheel.setCyclic(true);
                hourWheel.setInterpolator(new AnticipateOvershootInterpolator());

                minuteWheel.setAdapter(new StrericWheelAdapter(minuteContent));
                minuteWheel.setCurrentItem(curMinute);
                minuteWheel.setCyclic(true);
                minuteWheel.setInterpolator(new AnticipateOvershootInterpolator());

                builder.setTitle("选取时间");
                builder.setPositiveButton("确  定", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        StringBuffer sb = new StringBuffer();
                        sb.append(yearWheel.getCurrentItemValue()).append("-").append(monthWheel.getCurrentItemValue())
                                .append("-").append(dayWheel.getCurrentItemValue());

                        sb.append(" ");
                        sb.append(hourWheel.getCurrentItemValue()).append(":")
                                .append(minuteWheel.getCurrentItemValue());
                        timeedit1.setText(sb);
                        dialog.cancel();
                    }
                });

                builder.show();

            }
                break;
            default:
                break;
        }
    }

    private void upload() {
        if (task_DEF_KEY_.equals("sealback")) {
            if (nextPeople.getText().equals("请选择处理人")) {
                // Toast.makeText(context, "请选择下一步处理人",
                // Toast.LENGTH_SHORT).show();
                ToastHelp.doToast(context, "请选择下一步处理人");
                return;
            }

            if (timeedit.getText().equals("请填写归还时间")) {
                // Toast.makeText(context, "请选择归还时间",
                // Toast.LENGTH_SHORT).show();
                ToastHelp.doToast(context, "请选择归还时间");
            } else {
                UpLoadInfo1 upload1 = new UpLoadInfo1("retruntime_long");
                upload1.execute();
            }
        } else if (task_DEF_KEY_.equals("comfirmback")) {
            if (timeedit.getText().equals("请填写归还时间")) {
                // Toast.makeText(context, "请选择归还时间",
                // Toast.LENGTH_SHORT).show();
                ToastHelp.doToast(context, "请选择归还时间");
            } else {
                UpLoadInfo1 upload1 = new UpLoadInfo1("receivetime_long");
                upload1.execute();
            }

        } else if(type.contains("outgoing"))
        {
           String arg = ((TextView)main_view.findViewById(R.id.timeText)).getText().toString();
            String arg1 = ((EditText)main_view.findViewById(R.id.editText7)).getText().toString();
            String arg2 = ((EditText)main_view.findViewById(R.id.editText8)).getText().toString();
            String arg3 = ((EditText)main_view.findViewById(R.id.editText9)).getText().toString();


            if (isAgree.getText().equals("同意") || isAgree.getText().equals("确认还款")) {
                UpLoadInfo upload = new UpLoadInfo("true");
                upload.execute(arg,arg1,arg2,arg3);
            } else if (isAgree.getText().equals("驳回")) {
                UpLoadInfo upload = new UpLoadInfo("false");
                upload.execute(arg,arg1,arg2,arg3);
            } else {
                // Toast.makeText(context, "请选择是否同意",
                // Toast.LENGTH_SHORT).show();
                ToastHelp.doToast(context, "请选择是否同意");
            }


        }else {
            if (isAgree.getText().equals("同意") || isAgree.getText().equals("确认还款")) {
                UpLoadInfo upload = new UpLoadInfo("true");
                upload.execute();
            } else if (isAgree.getText().equals("驳回")) {
                UpLoadInfo upload = new UpLoadInfo("false");
                upload.execute();
            } else {
                // Toast.makeText(context, "请选择是否同意",
                // Toast.LENGTH_SHORT).show();
                ToastHelp.doToast(context, "请选择是否同意");
            }
        }

    }

    private class UpLoadInfo1 extends AsyncTask<String, Integer, String> {
        private String task;
        private String textContent;

        // private ProgressDialog mProgress;
        public UpLoadInfo1(String task) {
            this.task = task;
            this.textContent = timeedit.getText().toString();
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... params) {
            String result = null;
            HttpResponse response = null;
            BufferedReader reader = null;
            try {

                ArrayList<NameValuePair> vs = new ArrayList<NameValuePair>();

                String times = "";
                try {
                    SimpleDateFormat mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    // 继续转换得到秒数的long型
                    Date time = mFormat.parse(textContent);

                    long dtime = time.getTime();
                    times = "" + dtime;
                } catch (Exception e) {
                    // TODO: handle exception
                }

                vs.add(new BasicNameValuePair(task, times));

                if (task_DEF_KEY_.equals("sealback") && peoples_next.size() > 0) {
                    vs.add(new BasicNameValuePair("workUserId", workUserId));
                }
                System.out.println("workUserId==" + workUserId);

                response = LinkHelp.post(URLS.getTaskDeal(taskId, type), vs, false);

                if (response != null) {
                    StatusLine line = response.getStatusLine();
                    if (line.getStatusCode() == 200) {
                        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                        StringBuilder sb = new StringBuilder();
                        for (String s = reader.readLine(); s != null; s = reader.readLine()) {
                            sb.append(s);
                        }
                        reader.close();
                        result = sb.toString();

                        System.out.println(result);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }

        @Override
        protected void onPostExecute(String result) {

            if (result == null) {
                ToastHelp.doToast(context, "网络异常！");
                return;
            }

            JSONObject jsonObject;
            try {
                jsonObject = new JSONObject(result);
                if (jsonObject.isNull("code")) {
                    String status = jsonObject.getString("status");
                    UserInfo info = UserInfo.getUserInfor();
                    if (status.equals("success")) {
                        Toast.makeText(context, "提交成功", Toast.LENGTH_SHORT).show();
                        {
                            // 首页任务状态刷新
                            // Intent mIntent = new
                            // Intent(MenuActivity.RECRIVE_BROADCAST);
                            // //发送广播
                            // sendBroadcast(mIntent);
                            MenuActivity.sendMsg();
                            TaskInfo.this.setResult(Activity.RESULT_OK, getIntent());

                        }
                        finish();
                    } else {
                        String msg = jsonObject.getString("msg");
                        // Toast.makeText(context, msg,
                        // Toast.LENGTH_SHORT).show();
                        ToastHelp.doToast(context, msg);
                    }

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

    }

    private class UpLoadInfo extends AsyncTask<String, Integer, String> {
        String isAgree;
        private MyLoadingDialog myLoaddialog;
        private String suggestionText;

        // private ProgressDialog mProgress;
        public UpLoadInfo(String isAgree) {

            this.isAgree = isAgree;
            this.suggestionText = suggestion.getText().toString();

        }


        @Override
        protected void onPreExecute() {
            myLoaddialog = new MyLoadingDialog(TaskInfo.this, null, "提交中...", false);
            super.onPreExecute();

        }

        @Override
        protected String doInBackground(String... params) {
            String result = null;
            HttpResponse response = null;
            BufferedReader reader = null;
            try {

                ArrayList<NameValuePair> vs = new ArrayList<NameValuePair>();


                vs.add(new BasicNameValuePair("fp_approvePass", isAgree));
                vs.add(new BasicNameValuePair("fp_auditReason",
                        suggestionText == null ? "" : suggestionText));

                if (type.contains("payForment") || type.contains("payForment-suz02")
                        || type.contains("payForment-suz01")) {
                    vs.add(new BasicNameValuePair("type", paytype));
                }

                if(type.contains("outgoing"))
                {
                    vs.add(new BasicNameValuePair("endDate",params[0]));
                    vs.add(new BasicNameValuePair("departMileage",params[1]));
                    vs.add(new BasicNameValuePair("returnMileage",params[2]));
                    vs.add(new BasicNameValuePair("totalMileage",params[3]));
                }
                response = LinkHelp.post(URLS.getTaskDeal(taskId, type), vs, false);

                if (response != null) {
                    StatusLine line = response.getStatusLine();
                    if (line.getStatusCode() == 200) {
                        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                        StringBuilder sb = new StringBuilder();
                        for (String s = reader.readLine(); s != null; s = reader.readLine()) {
                            sb.append(s);
                        }
                        reader.close();
                        result = sb.toString();

                        System.out.println(result);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }

        @Override
        protected void onPostExecute(String result) {
            myLoaddialog.dimiss();

            if (result == null) {
                ToastHelp.doToast(context, "网络异常！");
                return;
            }

            JSONObject jsonObject;
            try {
                jsonObject = new JSONObject(result);
                if (jsonObject.isNull("code")) {
                    String status = jsonObject.getString("status");
                    UserInfo info = UserInfo.getUserInfor();
                    if (status.equals("success")) {
                        Toast.makeText(context, "提交成功", Toast.LENGTH_SHORT).show();
                        {
                            // 首页任务状态刷新
                            // Intent mIntent = new
                            // Intent(MenuActivity.RECRIVE_BROADCAST);
                            // //发送广播
                            // sendBroadcast(mIntent);
                            MenuActivity.sendMsg();
                            TaskInfo.this.setResult(Activity.RESULT_OK, getIntent());
                        }

                        finish();
                    } else {
                        String msg = jsonObject.getString("msg");
                        // Toast.makeText(context, msg,
                        // Toast.LENGTH_SHORT).show();
                        ToastHelp.doToast(context, msg);
                    }

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

    }

    private void initPopView() {

        useCarDialog = new CommonDialog(this);

        String[] texts = new String[]{"同意", "驳回"};

        for (int i = 0; i < texts.length; i++) {
            final View item = (View) inflater.inflate(R.layout.common_dialog_item, null);
            final TextView text = (TextView) item.findViewById(R.id.item_text);
            text.setText(texts[i]);
            useCarDialog.addView(item);

            text.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    isAgree.setText(text.getText().toString());
                    useCarDialog.dismiss();
                }
            });
        }

    }

    private class LoadTaskInfo extends AsyncTask<String, Integer, String> {

        private final String CODE = "code";
        private MyLoadingDialog dialog;

        @Override
        protected void onPreExecute() {
            dialog = new MyLoadingDialog(context, null, "加载中...", false);
        }

        @Override
        protected String doInBackground(String... params) {
            String result = null;
            HttpResponse response = null;
            BufferedReader reader = null;
            try {
                ArrayList<NameValuePair> vs = new ArrayList<NameValuePair>();
                vs.add(new BasicNameValuePair("taskId", taskId));
                vs.add(new BasicNameValuePair("processInstanceId", processId));
                vs.add(new BasicNameValuePair("processType", type));
                vs.add(new BasicNameValuePair("userId", UserInfo.getUserInfor().getId()));
                response = LinkHelp.post(URLS.getProcessInfo(), vs, true);
                if (response != null) {
                    StatusLine line = response.getStatusLine();
                    if (line.getStatusCode() == 200) {
                        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                        StringBuilder sb = new StringBuilder();
                        for (String s = reader.readLine(); s != null; s = reader.readLine()) {
                            sb.append(s);
                        }
                        result = sb.toString();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return result;
        }

        @Override
        protected void onPostExecute(String result) {
            dialog.dimiss();

            if (result == null) {
                ToastHelp.doToast(context, "网络异常！");
                return;
            }

            if (!TextUtils.isEmpty(result)) {

                if (result.contains("error")) {
                    // Toast.makeText(context, "数据获取错误",
                    // Toast.LENGTH_SHORT).show();
                    ToastHelp.doToast(context, "数据获取错误");
                } else if(result.contains("needLogin")) {
                    ToastHelp.doToast(context, "会话过期，请重新登录");
                    //注销jpush
                    Set<String> sets = new HashSet<>();
                    JPushInterface.setAliasAndTags(VenadaOAApplication.getInstance(), "", sets);
                    Intent launchIntent = context.getPackageManager().
                            getLaunchIntentForPackage("com.example.hcd");
                    launchIntent.setFlags(
                            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                    launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    context.startActivity(launchIntent);
                    return;
                }
                else

                {
                    if (isTaskTodo) {
                        initTaskTodoInfo();
                    }

                    if (type.contains("ExpenseSale") || type.contains("ExpenseSale-suz")) {
                        // 初始化附件
                        {
                            gridView = (MyGridView) findViewById(R.id.file_gridview);
                        }
                        ParseData parse = new ParseData();
                        ReimburseData data = parse.getRiemburseDetail(result);
                        initReimburseDetail(data);
                    } else if (type.contains("payForment") || type.contains("payForment-suz02")
                            || type.equals("payForment-suz01")) {
                        // 初始化附件
                        {
                            gridView = (MyGridView) findViewById(R.id.file_gridview);
                        }
                        ParseData parse = new ParseData();
                        PaymentData data = parse.getPaymentDetail(result, type);
                        initPaymentDetail(data);

                        paytype = data.getType();

                    } else if (type.contains("borrow")) {
                        ParseData parse = new ParseData();
                        BorrowData data = parse.getBorrowDetail(result, type);
                        initBorrowDetail(data);
                    } else if (type.contains("purchase")) {
                        // 初始化附件
                        {
                            gridView = (MyGridView) findViewById(R.id.file_gridview);
                        }
                        ParseData parse = new ParseData();
                        PurchaseData data = parse.getPurchaseDetail(result, type);
                        initPurchaseDetail(data);
                    } else if (type.contains("sealApp")) {
                        ParseData parse = new ParseData();
                        SealuseData data = parse.getSealUserDetail(result, type);
                        initSealUseDetail(data);
                    } else if (type.contains("workOvertime")) {
                        ParseData parse = new ParseData();
                        OverTimeData data = parse.getOverTimeDetail(result, type);
                        initOverTimeDetail(data);
                    } else if (type.contains("daysOff")) {
                        ParseData parse = new ParseData();
                        OverTimeData data = parse.getOffDetail(result, type);
                        initOverTimeDetail(data);
                    } else if (type.contains("leave")) {
                        ParseData parse = new ParseData();
                        LeaveData data = parse.getLeaveDetail(result, type);
                        initLeaveDetail(data);
                    } else if (type.contains("outgoing")) {
                        ParseData parse = new ParseData();
                        UseCarData data = parse.getUseCarDetail(result, type);
                        initUseCarDetail(data);
                    } else if (type.contains("businessTravel")) {
                        ParseData parse = new ParseData();
                        BusniessTravelData data = parse.getBusinessDetail(result, type);
                        initBusinsessDetail(data);
                    }

                    if (isTaskTodo) {
                        // 获取下一步处理人
                        getNextPeople next = new getNextPeople();
                        next.execute();
                    }
                }

            }
        }

    }

    private void initReimburseDetail(ReimburseData data) {

        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            // 初始化详情界面
            EditText edit;
            // 标题
            edit = (EditText) main_view.findViewById(R.id.editText);
            edit.setText(data.getProcessInstanceId() + "#" + data.getTitle());
            // 流程状态
            edit = (EditText) main_view.findViewById(R.id.editText1);
            edit.setText(data.getProcessStatus());
            // 报销时间
            edit = (EditText) main_view.findViewById(R.id.editText2);
            edit.setText(data.getCreatetime());
            // 报销项目
            TextView pro_name = (TextView) main_view.findViewById(R.id.title31);
            pro_name.setText(data.getProjectName());

            if (data.getBorrow() != null && !isShowReimburseOrBorrow) {
                if (data.getBorrow().getProcessInstanceId() != null) {
                    final String pricessId = data.getBorrow().getProcessInstanceId();
                    pro_name = (TextView) main_view.findViewById(R.id.title313);
                    pro_name.setText(pricessId);

                    pro_name.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            // TODO Auto-generated method stub
                            Intent intent = new Intent(context, TaskInfo.class);
                            intent.putExtra("processId", pricessId);
                            intent.putExtra("TASK_TYPE", "borrow");
                            intent.putExtra("IS_TASK_TODO", false);
                            intent.putExtra("IS_RELATATION", false);
                            intent.putExtra("NO_SHOW_REIMBURSE_BORROW", true);
                            startActivity(intent);
                        }
                    });

                }
            } else {
                findViewById(R.id.is_have_borrow).setVisibility(View.GONE);
            }

            // 报销用途
            if (data.getReimburseUseinfoList().size() > 0) {
                final LinearLayout layout = (LinearLayout) main_view.findViewById(R.id.addlineproject);
                for (ProjectChildData childData : data.getReimburseUseinfoList()) {
                    final View item = (View) inflater.inflate(R.layout.info_money_item, null);
                    TextView info = (TextView) item.findViewById(R.id.textinfo);
                    info.setText(childData.info);

                    TextView num = (TextView) item.findViewById(R.id.textnum);

                    DecimalFormat nf = new DecimalFormat("#0.00");
                    nf.setGroupingUsed(false);
                    num.setText(nf.format(childData.numOfmoney));

                    EditText numOfmoney = (EditText) item.findViewById(R.id.editText2);
                    numOfmoney.setEnabled(false);

                    numOfmoney = (EditText) item.findViewById(R.id.editText1);

                    numOfmoney.setEnabled(false);
                    layout.addView(item);
                }
            }

            // 报销合计
            edit = (EditText) main_view.findViewById(R.id.editText5);

            DecimalFormat nf = new DecimalFormat("#0.00");
            nf.setGroupingUsed(false);
            edit.setText(nf.format(data.getAmount()));
            // 大写金额
            edit = (EditText) main_view.findViewById(R.id.editText6);
            edit.setText(DigitalTool.toBigMode(data.getAmount()));

            // 借款人
            edit = (EditText) main_view.findViewById(R.id.editText7);
            edit.setText(data.getApplicant());
            // 备注
            TextView remark = (TextView) main_view.findViewById(R.id.textinfomore);
            remark.setText(Html.fromHtml(data.getRemark(), new URLImageParser(remark, this), null));

            remark = (TextView) main_view.findViewById(R.id.title52);

            if (data.getIshasReceipt() != null) {
                if (data.getIshasReceipt().equals("yes")) {
                    remark.setText("有票");
                } else if (data.getIshasReceipt().equals("no")) {
                    remark.setText("无票");
                }
            } else {
                remark.setText(" - - ");
            }

            Id = data.getId();
            // 实力化几个ImageAndText 对象
            listImageAndText = new ArrayList<ImageAndText>();
            for (int i = 0; i < data.getImageList().size(); i++) {
                ImageAndText iat = new ImageAndText(
                        data.getImgPrefix() + data.getImageList().get(i).getImageFilePath(),
                        data.getImgPrefix() + data.getImageList().get(i).getImageFilePath());
                listImageAndText.add(iat);
            }

            if (listImageAndText.size() == 0) {
                main_view.findViewById(R.id.appendix_bg).setVisibility(View.GONE);
            }

            adapter = new ImageAndTextListAdapter(TaskInfo.this, listImageAndText, gridView);
            gridView.setAdapter(adapter);

            gridView.setOnItemClickListener(this);

        }
    }

    private void initPaymentDetail(PaymentData data) {
        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            // 初始化详情界面
            EditText edit;
            // 标题
            edit = (EditText) main_view.findViewById(R.id.editText);
            edit.setText(data.getProcessId() + "#" + data.getTitle());
            // 流程状态
            edit = (EditText) main_view.findViewById(R.id.editText1);
            edit.setText(data.getProcessStatus());
            // 付款類型
            edit = (EditText) main_view.findViewById(R.id.editText2);
            edit.setText(data.getTypeName());
            // 申請人
            edit = (EditText) main_view.findViewById(R.id.editText3);
            edit.setText(data.getApplicant());
            // 收款單位
            edit = (EditText) main_view.findViewById(R.id.editText4);
            edit.setText(data.getGatheringManName());

            // 申請時間
            edit = (EditText) main_view.findViewById(R.id.editText5);
            edit.setText(data.getActionTime());
            // 金额
            edit = (EditText) main_view.findViewById(R.id.editText6);
            DecimalFormat nf = new DecimalFormat("#0.00");
            nf.setGroupingUsed(false);
            edit.setText(nf.format(data.getAmount()));
            // 大寫金額
            edit = (EditText) main_view.findViewById(R.id.editText7);
            edit.setText(DigitalTool.toBigMode(Double.parseDouble("" + data.getAmount())));
            // 開戶銀行
            edit = (EditText) main_view.findViewById(R.id.editText8);
            edit.setText(data.getBankName());
            // 銀行賬戶
            edit = (EditText) main_view.findViewById(R.id.editText9);
            edit.setText(data.getBankCardId());
            // 稅號
            edit = (EditText) main_view.findViewById(R.id.editText10);
            edit.setText(data.getTaxNumber());
            // 付款理由
            edit = (EditText) main_view.findViewById(R.id.editText11);
            edit.setText(Html.fromHtml(data.getReason(), new URLImageParser(edit, this), null));


            TextView remark = (TextView) main_view.findViewById(R.id.title52);
            if (data.getIshasReceipt() != null) {
                if (data.getIshasReceipt().equals("yes")) {
                    remark.setText("有票");
                } else if (data.getIshasReceipt().equals("no")) {
                    remark.setText("无票");
                }
            }

            Id = data.getId();
            // 实力化几个ImageAndText 对象
            listImageAndText = new ArrayList<ImageAndText>();

            for (int i = 0; i < data.getImageList().size(); i++) {
                ImageAndText iat = new ImageAndText(
                        data.getImgPrefix() + data.getImageList().get(i).getImageFilePath(),
                        data.getImageList().get(i).getImageFilePath());
                listImageAndText.add(iat);
            }

            if (listImageAndText.size() == 0) {
                main_view.findViewById(R.id.appendix_bg).setVisibility(View.GONE);
            }

            adapter = new ImageAndTextListAdapter(TaskInfo.this, listImageAndText, gridView);
            gridView.setAdapter(adapter);

            gridView.setOnItemClickListener(this);
        }
    }

    private void initBorrowDetail(BorrowData data) {
        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            // 初始化详情界面
            EditText edit;
            // 标题
            edit = (EditText) main_view.findViewById(R.id.editText);
            edit.setText(data.getProcessInstanceId() + "#" + data.getTitle());
            // 流程状态
            edit = (EditText) main_view.findViewById(R.id.editText2);
            edit.setText(data.getProcessStatus());

            if (data.getProcessStatus().contains("确认还款")) {
                isSureBackMoney = true;

                if (isTaskTodo) {
                    isAgree.setText("确认还款");
                }

                main_view.findViewById(R.id.btn_image1).setVisibility(View.GONE);
            }

            // 金額
            DecimalFormat nf = new DecimalFormat("#0.00");
            nf.setGroupingUsed(false);

            edit = (EditText) main_view.findViewById(R.id.editText3);
            edit.setText(nf.format(Double.parseDouble(data.getAmount())));
            // 大寫
            edit = (EditText) main_view.findViewById(R.id.editText4);
            edit.setText(DigitalTool.toBigMode(Double.parseDouble("" + data.getAmount())));

            TextView viewrei = (TextView) main_view.findViewById(R.id.title413);

            if (data.getReimburseList().size() > 0 && !isShowReimburseOrBorrow) {
                initPopView2(data.getReimburseList());
                viewrei.setOnClickListener(this);

                edit = (EditText) main_view.findViewById(R.id.title415);
                edit.setText(nf.format(data.getReimburSum()));
                // 大寫
                edit = (EditText) main_view.findViewById(R.id.title417);
                edit.setText(DigitalTool.toBigMode(data.getReimburSum()));

                edit = (EditText) main_view.findViewById(R.id.title419);
                edit.setText(nf.format(data.getDiffPrice()));
                // 大寫
                edit = (EditText) main_view.findViewById(R.id.title421);
                edit.setText(DigitalTool.toBigMode(data.getDiffPrice()));

                if (data.getDiffPrice() > 0.000001) {
                    TextView title = (TextView) main_view.findViewById(R.id.title418);
                    title.setText("应退金额");

                } else if (data.getDiffPrice() < -0.000001) {

                } else {
                    RelativeLayout bg = (RelativeLayout) main_view.findViewById(R.id.acount_result_big);
                    bg.setVisibility(View.GONE);

                    bg = (RelativeLayout) main_view.findViewById(R.id.acount_result);
                    bg.setVisibility(View.GONE);
                }

            } else {
                LinearLayout view = (LinearLayout) main_view.findViewById(R.id.is_have_borrow);
                view.setVisibility(View.GONE);
            }

            if (data.getType() == null || data.getType().equals("")) {
                // 银行
                edit = (EditText) main_view.findViewById(R.id.editText5);
                edit.setText(data.getBank());

                // 银行卡号
                edit = (EditText) main_view.findViewById(R.id.editText51);
                edit.setText(data.getNumofbank());

            } else {
                RelativeLayout view = (RelativeLayout) main_view.findViewById(R.id.bank_of_name);
                // 银行
                view.setVisibility(View.GONE);
                // 银行卡号
                view = (RelativeLayout) main_view.findViewById(R.id.bank_of_num);
                view.setVisibility(View.GONE);
                // 银行卡号
                edit = (EditText) main_view.findViewById(R.id.editText52);
                edit.setText(data.getType());
                view = (RelativeLayout) main_view.findViewById(R.id.way_of_borrow);
                view.setVisibility(View.VISIBLE);
            }

            // 借款人
            edit = (EditText) main_view.findViewById(R.id.editText6);
            edit.setText(data.getApplicant());
            // 理由
            edit = (EditText) main_view.findViewById(R.id.editText7);
            edit.setText(Html.fromHtml(data.getRemark(), new URLImageParser(edit, this), null));

            // 借款時間
            edit = (EditText) main_view.findViewById(R.id.editText8);
            edit.setText(data.getBorrowTime());

            final String idandtitle = data.getProcessInstanceId() + "#" + data.getTitle();
            final String Id = data.getID();
            if (isRelation) {
                RelativeLayout view = (RelativeLayout) main_view.findViewById(R.id.ishaveRelation);
                view.setVisibility(View.VISIBLE);

                TextView relativeBtn = (TextView) main_view.findViewById(R.id.relative);
                relativeBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        getIntent().putExtra("borrow_processid", idandtitle);
                        getIntent().putExtra("Id", Id);
                        context.setResult(Activity.RESULT_OK, getIntent());
                        finish();
                    }
                });

                relativeBtn = (TextView) main_view.findViewById(R.id.no_relative);
                relativeBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        finish();
                    }
                });
            }

            // 下一步处理人Html.fromHtml(data.getRemark(), null, new
            // MxgsaTagHandler(this))
            // edit = (EditText)main_view.findViewById(R.id.editText9);
            // edit.setText();
            // 单据凭证

            // 流程跟踪
            // edit = (EditText)main_view.findViewById(R.id.editText);
            // edit.setText();
        }
    }

    private void initPurchaseDetail(PurchaseData data) {
        if (data == null) {
            System.out.println("解析采购数据失败");
        } else {
            // 初始化详情界面
            EditText edit;
            // 标题
            edit = (EditText) main_view.findViewById(R.id.editText);
            edit.setText(data.getProcessInstanceId() + "#" + data.getTitle());
            // 流程状态
            edit = (EditText) main_view.findViewById(R.id.editText1);
            edit.setText(data.getProcessStatus());
            // 所属项目
            TextView edit1 = (TextView) main_view.findViewById(R.id.title21);
            edit1.setText(data.getProjectName());

            EditText edit6 = (EditText) main_view.findViewById(R.id.editText6);
            edit6.setText(data.getUseSeal());
            // 付款方式
            edit1 = (TextView) main_view.findViewById(R.id.title31);
            edit1.setText(InternetKeep.getInstence().getPayTypeByID(data.getPurchaseType()));
            if (edit1.getText().equals("现金")) {
                LinearLayout bankbg = (LinearLayout) main_view.findViewById(R.id.bankbg);
                bankbg.setVisibility(View.GONE);
            } else {
                if (edit1.getText().toString().equals("") || edit1.getText().toString() == null) {
                    edit1.setText("获取类型失败");

                } else {
                    // 供应商
                    edit = (EditText) main_view.findViewById(R.id.editText4);
                    edit.setText(data.getSupplierName());

                    // 供应商银行
                    edit = (EditText) main_view.findViewById(R.id.editText5);
                    edit.setText(data.getBankName());
                    // 供应商银行账号
//                    edit = (EditText) main_view.findViewById(R.id.editText6);
//                    edit.setText("" + data.getBankCardId());
                }

            }

            // 申请时间
            edit = (EditText) main_view.findViewById(R.id.editText7);
            edit.setText(data.getPurchaseTime());
            // 金额
            edit = (EditText) main_view.findViewById(R.id.editText8);
            DecimalFormat nf = new DecimalFormat("#0.00");
            nf.setGroupingUsed(false);
            edit.setText(nf.format(Double.parseDouble(data.getAmount())));
            // 大写金额
            edit = (EditText) main_view.findViewById(R.id.editText9);
            edit.setText(DigitalTool.toBigMode(Double.parseDouble("" + data.getAmount())));
            // 申请人
            edit = (EditText) main_view.findViewById(R.id.editText10);
            edit.setText(data.getApplicant());
            // 采购商品信息
            edit = (EditText) main_view.findViewById(R.id.editText11);
            edit.setText( Html.fromHtml(data.getReason(), new URLImageParser(edit, this), null));

            TextView remark = (TextView) main_view.findViewById(R.id.title52);
            if (data.getIshasReceipt() != null) {
                if (data.getIshasReceipt().equals("yes")) {
                    remark.setText("有票");
                } else if (data.getIshasReceipt().equals("no")) {
                    remark.setText("无票");
                }
            }

            Id = data.getID();
            // 实力化几个ImageAndText 对象
            listImageAndText = new ArrayList<ImageAndText>();
            for (int i = 0; i < data.getImageList().size(); i++) {
                ImageAndText iat = new ImageAndText(
                        data.getImgPrefix() + data.getImageList().get(i).getImageFilePath(),
                        data.getImageList().get(i).getImageFilePath());
                listImageAndText.add(iat);
            }

            if (listImageAndText.size() == 0) {
                main_view.findViewById(R.id.appendix_bg).setVisibility(View.GONE);
            }
            adapter = new ImageAndTextListAdapter(TaskInfo.this, listImageAndText, gridView);
            gridView.setAdapter(adapter);

            gridView.setOnItemClickListener(this);
        }
    }

    // 用章申請初始化
    private void initSealUseDetail(SealuseData data) {
        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            EditText edittext = (EditText) main_view.findViewById(R.id.editText);
            edittext.setText(data.getApplicant());

            edittext = (EditText) main_view.findViewById(R.id.editText1);
            edittext.setText(data.getProcessStatus());

            edittext = (EditText) main_view.findViewById(R.id.editText2);
            edittext.setText(data.getSealName());

            edittext = (EditText) main_view.findViewById(R.id.editText3);

            if (data.getIsLendingout().equals("true")) {
                edittext.setText("是");
                edittext = (EditText) main_view.findViewById(R.id.editText4);

                if (data.getReceivetime() != null) {
                    edittext.setText(data.getReceivetime());
                } else {

                    edittext.setText(data.getEstimereturn(true));
                }
                if(data.getProcessStatus().contains("确认外借时间"))
                {
                    main_view.findViewById(R.id.yuji_return).setVisibility(View.GONE);
                    ((TextView)main_view.findViewById(R.id.title8)).setText("外借时间");
                    ((TextView)main_view.findViewById(R.id.title81)).setText("请填写外借时间");
                    view_title.setText("确认外借时间");
                }
                if(data.getProcessStatus().contains("确认归还时间"))
                {
                    main_view.findViewById(R.id.yuji_return).setVisibility(View.GONE);
                    view_title.setText("确认归还时间");
                }
                if(data.getProcessStatus().contains("财务确认"))
                {
                    main_view.findViewById(R.id.yuji_return).setVisibility(View.GONE);
                    main_view.findViewById(R.id.is_lendout).setVisibility(View.GONE);
                }
            } else {
                edittext.setText("否");
                RelativeLayout islend = (RelativeLayout) main_view.findViewById(R.id.is_lendout);
                islend.setVisibility(View.GONE);
            }



            edittext = (EditText) main_view.findViewById(R.id.editText5);
            edittext.setText(data.getCreatetime());

            edittext = (EditText) main_view.findViewById(R.id.editText6);
            edittext.setText(Html.fromHtml(data.getRemark(), new URLImageParser(edittext, this), null));


        }

    }

    private void initOverTimeDetail(OverTimeData data) {
        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            EditText edittext = (EditText) main_view.findViewById(R.id.editText);
            edittext.setText(data.getProcessInstanceId() + "#" + data.getApplicant());

            edittext = (EditText) main_view.findViewById(R.id.editText1);
            edittext.setText(data.getProcessStatus());

            edittext = (EditText) main_view.findViewById(R.id.editText2);
            edittext.setText(data.getOvertimeReason());

            TextView text = (TextView) main_view.findViewById(R.id.editText32);
            text.setText(data.getStartTime());

            text = (TextView) main_view.findViewById(R.id.editText33);
            text.setText(data.getEndTime());

            edittext = (EditText) main_view.findViewById(R.id.editText4);

            edittext.setText(data.getAllTime());
        }

    }

    private void initLeaveDetail(LeaveData data) {
        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            EditText edittext = (EditText) main_view.findViewById(R.id.editText);
            edittext.setText(data.getProcessInstanceId() + "#" + data.getApplicant());

            edittext = (EditText) main_view.findViewById(R.id.editText1);
            edittext.setText(data.getProcessStatus());

            edittext = (EditText) main_view.findViewById(R.id.editText2);
            edittext.setText(data.getReason());

            TextView text = (TextView) main_view.findViewById(R.id.editText32);
            text.setText(data.getStartTime());

            text = (TextView) main_view.findViewById(R.id.editText33);
            text.setText(data.getEndTime());

            text = (TextView) main_view.findViewById(R.id.title41);

            text.setText(data.getLeaveType());
        }

    }

    private void initOutDetail(OutData data) {
        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            EditText edittext = (EditText) main_view.findViewById(R.id.editText);
            edittext.setText(data.getProcessInstanceId() + "#" + data.getApplicant());

            edittext = (EditText) main_view.findViewById(R.id.editText1);
            edittext.setText(data.getProcessStatus());

            edittext = (EditText) main_view.findViewById(R.id.editText2);
            edittext.setText(data.getReason());

            TextView text = (TextView) main_view.findViewById(R.id.editText32);
            text.setText(data.getStartTime());

            text = (TextView) main_view.findViewById(R.id.editText33);
            text.setText(data.getEndTime());

            text = (TextView) main_view.findViewById(R.id.title41);
            if (data.getIscarout() != null) {
                if (data.getIscarout().equals("1")) {
                    text.setText("用车");
                } else {
                    text.setText("无车");
                }
            }

        }

    }

    private void initUseCarDetail(UseCarData data) {
        if (data == null) {
            System.out.println("解析数据失败");
        } else {
            EditText edittext = (EditText) main_view.findViewById(R.id.editText);
            edittext.setText(data.getProcessInstanceId() + "#" + data.getApplicant());

            edittext = (EditText) main_view.findViewById(R.id.editText1);
            edittext.setText(data.getProcessStatus());

            edittext = (EditText) main_view.findViewById(R.id.editText2);
            edittext.setText(data.getReason());

            edittext = (EditText) main_view.findViewById(R.id.editText3);
            edittext.setText(data.getStartData());

            TextView text = (TextView) main_view.findViewById(R.id.title41);
            text.setText(data.getPredictMileage()+"");

            if(data.getProcessStatus().contains("确认归还"))
            {
                main_view.findViewById(R.id.task_todo_bg).setVisibility(View.GONE);
                main_view.findViewById(R.id.sure_back).setVisibility(View.VISIBLE);
                timeedit1 =(TextView) main_view.findViewById(R.id.timeText);
                timeedit1.setOnClickListener(context);

            }

//            text = (TextView) main_view.findViewById(R.id.editText33);
//            text.setText(data.getEndDate());



        }

    }

    private void initBusinsessDetail(BusniessTravelData data) {
        if (data == null) {
            System.out.println("解析报销数据失败");
        } else {
            EditText edittext = (EditText) main_view.findViewById(R.id.editText);
            edittext.setText(data.getProcessInstanceId() + "#" + data.getTitle());

            edittext = (EditText) main_view.findViewById(R.id.process_status);
            edittext.setText(data.getProcessStatus());

            edittext = (EditText) main_view.findViewById(R.id.editText1);
            edittext.setText(data.getApplicant());

            edittext = (EditText) main_view.findViewById(R.id.editText2);
            edittext.setText(data.getToAddress());

            edittext = (EditText) main_view.findViewById(R.id.editText6);
            edittext.setText(data.getReason());

            TextView text = (TextView) main_view.findViewById(R.id.editText42);
            text.setText(data.getStartTime());

            text = (TextView) main_view.findViewById(R.id.editText43);
            text.setText(data.getEndTime());

            text = (TextView) main_view.findViewById(R.id.title31);
            text.setText(data.getTranType());

            text = (TextView) main_view.findViewById(R.id.title51);
            text.setText(data.getProjectName());
        }

    }

    // 获取下一步处理人
    private class getNextPeople extends AsyncTask<String, Integer, String> {

        // private ProgressDialog mProgress;
        public getNextPeople() {
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... params) {
            String result = null;
            HttpResponse response = null;
            BufferedReader reader = null;
            try {
                ArrayList<NameValuePair> vs = new ArrayList<NameValuePair>();
                vs.add(new BasicNameValuePair("taskId", taskId));

                if (type.contains("payForment") || type.contains("payForment-suz02")
                        || type.contains("payForment-suz01")) {
                    vs.add(new BasicNameValuePair("type", paytype));
                }

                response = LinkHelp.post(URLS.getNextWorkUser(type), vs, false);

                if (response != null) {
                    StatusLine line = response.getStatusLine();
                    if (line.getStatusCode() == 200) {
                        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                        StringBuilder sb = new StringBuilder();
                        for (String s = reader.readLine(); s != null; s = reader.readLine()) {
                            sb.append(s);
                        }
                        reader.close();
                        result = sb.toString();

                        System.out.println(result);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }

        @Override
        protected void onPostExecute(String result) {

            if (result == null) {
                ToastHelp.doToast(context, "网络异常！");
                return;
            }

            JSONObject jsonObject;
            try {
                jsonObject = new JSONObject(result);
                if (jsonObject.isNull("code")) {
                    String status = jsonObject.getString("status");
                    if (status.equals("success")) {
                        {
                            if (result.contains("workUserInfo")) {
                                JSONArray peoples = jsonObject.getJSONArray("workUserInfo");
                                for (int i = 0; i < peoples.length(); i++) {
                                    PeopleNextData data = new PeopleNextData();
                                    JSONObject myJS = peoples.getJSONObject(i);
                                    data.setUserId(myJS.getString("userId"));
                                    data.setUserName(myJS.getString("userName"));
                                    data.setDepartmentId(myJS.getString("departmentId"));
                                    data.setDepartmentName(myJS.getString("departmentName"));
                                    data.setCompanyId(myJS.getString("companyId"));
                                    data.setCompanyName(myJS.getString("companyName"));
                                    data.setIsHead(myJS.getString("isHead"));
                                    data.setCode(myJS.getString("code"));
                                    peoples_next.add(data);
                                }
                                if (peoples_next.size() == 1) {
                                    nextPeople.setText(peoples_next.get(0).getUserName() + "("
                                            + peoples_next.get(0).getDepartmentName() + ")");
                                    workUserId = peoples_next.get(0).getUserId();
                                } else if (peoples_next.size() > 1) {
                                    initPopView1();
                                } else if (peoples_next.size() <= 0) {
                                    nextPeople.setText("无");
                                    nextPeopleBg.setVisibility(View.GONE);
                                }

                            } else if (result.contains("noNeedWorkUserId")) {
                                if (jsonObject.getString("noNeedWorkUserId").equals("true")) {
                                    nextPeople.setText("下一步不需要处理人");
                                    nextPeopleBg.setVisibility(View.GONE);
                                }

                            } else if (result.contains("msg")) {
                                nextPeople.setText(jsonObject.getString("msg"));
                                if (jsonObject.getString("msg").contains("不需要")) {
                                    nextPeopleBg.setVisibility(View.GONE);
                                }
                            } else {
                                System.out.println("服务器数据错误！");
                            }

                        }

                    } else {
                        String msg = jsonObject.getString("msg");
                        // Toast.makeText(context, msg,
                        // Toast.LENGTH_SHORT).show();
                        ToastHelp.doToast(context, msg);
                        nextPeople.setText("空");
                        nextPeopleBg.setVisibility(View.GONE);
                    }

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

    }

    // 获取流程跟踪
    private class getFlowTrace extends AsyncTask<String, Integer, String> {

        // private ProgressDialog mProgress;
        public getFlowTrace() {
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(String... params) {
            String result = null;
            HttpResponse response = null;
            BufferedReader reader = null;
            try {
                ArrayList<NameValuePair> vs = new ArrayList<NameValuePair>();
                vs.add(new BasicNameValuePair("pid", processId));
                response = LinkHelp.post(URLS.getFlowTrace(), vs, false);

                if (response != null) {
                    StatusLine line = response.getStatusLine();
                    if (line.getStatusCode() == 200) {
                        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                        StringBuilder sb = new StringBuilder();
                        for (String s = reader.readLine(); s != null; s = reader.readLine()) {
                            sb.append(s);
                        }
                        reader.close();
                        result = sb.toString();

                        System.out.println(result);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return result;
        }

        @Override
        protected void onPostExecute(String result) {

            if (result == null) {
                ToastHelp.doToast(context, "网络异常！");
                return;
            }

            JSONObject jsonObject;
            try {
                jsonObject = new JSONObject(result);
                if (jsonObject.isNull("code")) {
                    String status = jsonObject.getString("status");
                    if (status.equals("success")) {
                        {

                            JSONArray peoples = jsonObject.getJSONArray("list");
                            for (int i = 0; i < peoples.length(); i++) {
                                TaskTodoInfo data = new TaskTodoInfo();
                                JSONObject myJS = peoples.getJSONObject(i);
                                data.setContent(myJS.isNull("content") ? "无" : myJS.getString("content"));
                                data.setAgree(myJS.getString("agree"));
                                data.setName_(myJS.getString("name_"));
                                data.setAssignee_(myJS.getString("assignee_"));
                                data.setCreate_TIME_(Long.parseLong(myJS.getString("create_TIME_")));
                                flowTraceList.add(data);
                            }

                            if (flowTraceList.size() > 0) {
                                for (TaskTodoInfo date : flowTraceList) {
                                    View flowItem = (View) inflater.inflate(R.layout.flow_trace_item, null);
                                    TextView name_dept = (TextView) flowItem.findViewById(R.id.name_dept_);
                                    name_dept.setText(date.getAssignee_() + "," + date.getName_());
                                    name_dept = (TextView) flowItem.findViewById(R.id.is_agree);
                                    name_dept.setText(date.getAgree());
                                    name_dept = (TextView) flowItem.findViewById(R.id.create_time);
                                    name_dept.setText(date.getCreate_TIME_());
                                    name_dept = (TextView) flowItem.findViewById(R.id.textinfomore);
                                    name_dept.setText(date.getContent());
                                    flowtrace.addView(flowItem);

                                }
                            }

                        }

                    } else {
                        String msg = jsonObject.getString("msg");
                        // Toast.makeText(context, msg,
                        // Toast.LENGTH_SHORT).show();
                        ToastHelp.doToast(context, msg);
                    }

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

    }

    // 初始化时钟
    public void initContent() {
        yearContent = new String[10];
        for (int i = 0; i < 10; i++)
            yearContent[i] = String.valueOf(i + 2013);

        monthContent = new String[12];
        for (int i = 0; i < 12; i++) {
            monthContent[i] = String.valueOf(i + 1);
            if (monthContent[i].length() < 2) {
                monthContent[i] = "0" + monthContent[i];
            }
        }

        dayContent = new String[31];
        for (int i = 0; i < 31; i++) {
            dayContent[i] = String.valueOf(i + 1);
            if (dayContent[i].length() < 2) {
                dayContent[i] = "0" + dayContent[i];
            }
        }
        hourContent = new String[24];
        for (int i = 0; i < 24; i++) {
            hourContent[i] = String.valueOf(i);
            if (hourContent[i].length() < 2) {
                hourContent[i] = "0" + hourContent[i];
            }
        }

        minuteContent = new String[60];
        for (int i = 0; i < 60; i++) {
            minuteContent[i] = String.valueOf(i);
            if (minuteContent[i].length() < 2) {
                minuteContent[i] = "0" + minuteContent[i];
            }
        }
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        ImageAndText uri = adapter.getItem(arg2);
        System.out.println(uri.getText());

        if (FileUtils.isPic(uri.getText())) {
            ArrayList<String> picpathlist = new ArrayList<String>();
            Intent intent = new Intent(context, ShowPictureList.class);
            for (int i = 0; i < listImageAndText.size(); i++) {
                if (FileUtils.isPic(listImageAndText.get(i).getText())) {
                    picpathlist.add(listImageAndText.get(i).getImageUrl());
                }
            }

            for (int i = 0; i < picpathlist.size(); i++) {
                if (picpathlist.get(i).equals(uri.getImageUrl())) {
                    intent.putExtra("MOREN_INDEX", i);
                }
            }

            intent.putStringArrayListExtra("PICK_PATH_LIST", picpathlist);

            intent.putExtra("IS_BENDI", false);
            startActivity(intent);
        } else {
            Intent intent = new Intent(TaskInfo.this, FileDetailActivity.class);
            intent.putExtra("FILE_URI", uri.getImageUrl());
            intent.putExtra("FILE_NAME", uri.getImageUrl());
            startActivity(intent);
        }

        overridePendingTransition(R.anim.out_alpha, R.anim.enter_alpha);
    }


}
